import { defineStore } from "pinia";
import { ref } from "vue";
import { deptCasList } from "@/api/setting.js";

export const useAdminStore = defineStore(
  'admin',
  () => {
    const deptList = ref('')
    const getDeptCasList = async () => {
      // console.log('部门列表')
      await deptCasList().then(res => {
        deptList.value = res.data.data
      })
      // console.log(deptList.value)
    }
    const deptSelectList = ref([])
    const getSelectList = (list) => {
      if (list.length > 0) {
        list.forEach(item => {
          deptSelectList.value.push({ id: item.id, name: item.name })
          if (item.children) {
            getSelectList(item.children)
          }
        })
      }
    }
    const removeDept = () => {
      deptList.value = ''
    }
    return {
      deptList,
      deptSelectList,
      getSelectList,
      getDeptCasList,
      removeDept
    }
  },
  {
    persist: true
  }
)